package cn.smartorigin.soas.frame.menubar;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.TexturePaint;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.border.Border;

import cn.smartorigin.soas.frame.SoasUtil;

public class CellRootMenu extends JMenu{

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color foregroundColor = SoasUtil.DEFAULT_TEXT_COLOR;
    private Image selectedBackgroundImageURL = new ImageIcon("img/menubar/menubar_background_selected.png").getImage();
    private TexturePaint paint = SoasUtil.createTexturePaint(selectedBackgroundImageURL);
    private Border border = BorderFactory.createEmptyBorder(0, 5, 0, 4);
    
    public CellRootMenu() {
        init();
    }

    public CellRootMenu(String text) {
        super(text);
        init();
    }
    
    private void init() {
        this.setFont(SoasUtil.FONT_14_BOLD);
        this.setBorder(border);
        this.setForeground(foregroundColor);
    }
    
    @Override
    protected void paintComponent(Graphics g) {

        if (this.isSelected()) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setPaint(paint);
            g2d.fillRect(0, 0, this.getWidth(), this.getHeight());

            super.paintComponent(g);
        } else {
            super.paintComponent(g);
        }
    }
}
